package com.quizzer.web.controller.question;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.quizzer.system.dto.question.question.QuestionAddDto;
import com.quizzer.system.dto.question.question.QuestionOutputDto;
import com.quizzer.system.dto.question.question.QuestionQueryDto;
import com.quizzer.system.dto.question.question.QuestionUpdateDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.quizzer.common.annotation.Log;
import com.quizzer.common.core.controller.BaseController;
import com.quizzer.common.core.domain.AjaxResult;
import com.quizzer.common.enums.BusinessType;
import com.quizzer.system.domain.Question;
import com.quizzer.system.service.IQuestionService;
import com.quizzer.common.utils.poi.ExcelUtil;
import com.quizzer.common.core.page.TableDataInfo;

/**
 * 题目Controller
 *
 * @author ruoyi
 * @date 2025-10-07
 */
@Api(tags = "题目接口")
@RestController
@RequestMapping("/question/question")
public class QuestionController extends BaseController
{
    @Autowired
    private IQuestionService questionService;

    /**
     * 查询题目列表
     */
    @ApiOperation("查询题目列表")
    @PreAuthorize("@ss.hasPermi('question:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuestionQueryDto question)
    {
        startPage();
        List<QuestionOutputDto> list = questionService.selectQuestionList(question);
        return getDataTable(list);
    }

    /**
     * 导出题目列表
     */
//    @ApiOperation("导出题目列表")
//    @PreAuthorize("@ss.hasPermi('question:question:export')")
//    @Log(title = "题目", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Question question)
//    {
//        List<Question> list = questionService.selectQuestionList(question);
//        ExcelUtil<Question> util = new ExcelUtil<Question>(Question.class);
//        util.exportExcel(response, list, "题目数据");
//    }

    /**
     * 获取题目详细信息
     */
    @ApiOperation("获取题目详细信息")
    @PreAuthorize("@ss.hasPermi('question:question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(questionService.selectQuestionById(id));
    }

    /**
     * 新增题目
     */
    @ApiOperation("新增题目")
    @PreAuthorize("@ss.hasPermi('question:question:add')")
    @Log(title = "题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionAddDto question)
    {
        return toAjax(questionService.insertQuestion(question));
    }

    /**
     * 修改题目
     */
    @ApiOperation("修改题目")
    @PreAuthorize("@ss.hasPermi('question:question:edit')")
    @Log(title = "题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionUpdateDto question)
    {
        return toAjax(questionService.updateQuestion(question));
    }

    /**
     * 删除题目
     */
    @ApiOperation("删除题目")
    @PreAuthorize("@ss.hasPermi('question:question:remove')")
    @Log(title = "题目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(questionService.deleteQuestionByIds(ids));
    }
}
